function main() {
    //新增页面
    if ($this.pageType == 'add') {
        if ($this.$store.state.user.tabs[$this.$store.state.user.tabs.length - 1]) {
            let applicationdata = $this.$store.state.user.tabs[$this.$store.state.user.tabs.length - 1].applicationdata
            if (applicationdata !== undefined && applicationdata !== "") {
                $this.model["selectStr_1690186702521_3m6iA"] = applicationdata[0].项目编号;//项目编号
                $this.model["input_1690186769700_NQIMN"] = applicationdata[0].项目名称;//项目名称
                $this.model["table_1761621684298_7OBB8"] = [];//表体

                //每条立项单
                for (let i = 0; i < applicationdata.length; i++) {
                    let url = $this.$util.getAPI_URL();
                    let formData = new FormData();
                    let currentBillId = applicationdata[i]["bill_id"]; // Capture the variable in local scope
                    formData.append("id", currentBillId);
                    formData.append("billId", $this.model.bill_id); //项目状态变更-billId
                    let whId = '19f7767608ad9cb441f791e89632031b'; //项目状态变更 - whId

                    $this.$http.post("/formsBusiness/shishilixiangbyId/", formData).then((res) => {
                        if (res.data.code === 280) {
                            let data = res.data.data
                            console.log("data = ",data);

                            //去掉首位空格+空格分割
                            let tempArr = data[0]["select_1761305206653_XuW8g"];
                            // 1. 去掉首尾空格（保险）
                            let rawStr = tempArr.trim();
                            // 2. 解析成数组
                            let idArr = JSON.parse(rawStr);   // 现在才是真正意义上的数组
                            console.log("设备数组 = ",idArr);

                            // 3. 循环 + switch 映射
                            let tempSet = new Set();
                            for (let idx = 0; idx < idArr.length; idx++) {
                                let id   = idArr[idx];
                                let name = '';
                                switch (id) {
                                    case '47a2c5b1ea1a3f14c29e96c65579a7aa': name = '高压变频器'; break;
                                    case '145adcede8748ba49f7eae7ae44868ef': name = '有源滤波器'; break;
                                    case 'f2f4e74e99f7d5714d5c3c4d8187bde8': name = '固态软启动'; break;
                                    case 'bf958dd85562bf779b26a50aa3877329': name = '维修服务';   break;
                                    case 'c13556e04b14c190bc51ac0a0b5e8fb0': name = '技术服务';   break;
                                    case '9cf8331436d1f29410c2351ea640da3b': name = '工程型变频器'; break;
                                    case 'ebe30a1cc2742d41c7508d6f969c370f': name = '自产软件';   break;
                                    case '232658f324af246776f3520be322ff3f': name = '调整项';     break;
                                    case '0bbaf97e2250f7f8ca3defa4327635c3': name = '岸电电源';   break;
                                    case '47610efb368d8b61ee6d3c5507bde2a2': name = '测试台';     break;
                                    case 'eb31441c15d4a595446a10c4342ef981': name = '服务-6%';    break;
                                    case '3ca36386ea2a82c1c231acb0d4d14529': name = '服务-13%';   break;
                                    case '269179be3c2c8b3c128ffe54b63e0b67': name = '备件';       break;
                                    case 'd1d31ce38718f53d646d3bad0d30b74d': name = '其他';       break;
                                    default:                                  name = '';          break;
                                }
                                if (name) tempSet.add(name);
                            }

                            // 4. 转数组
                            let nameArr = [...tempSet];
                            console.log(nameArr);

                            //处理表头
                            $this.model.selectStr_1690186702521_3m6iA = data[0]["input_1753770946444_03PAF"] //项目编号
                            $this.model.input_1690186769700_NQIMN = data[0]["input_1688608734780_FzYra"] //项目名称
                            //客户信息
                            $this.model.input_1761619590973_IbOMB = data[0]["input_1753771160383_nWyzU"] //最终客户名称
                            $this.model.input_1761620910643_ju9rd = data[0]["input_1688608906477_jFYCL"] //签约客户名称
                            $this.model.input_1761619590973_MNIfw = data[0]["input_1753770760663_1rG1x"] //最终客户联系人
                            $this.model.input_1761619590973_CV33P = data[0]["input_1753770705078_trNYj"] //签约客户联系人
                            $this.model.input_1761619590973_G6qDf = data[0]["input_1753770763601_aQcRL"] //最终客户联系电话
                            $this.model.input_1761619590973_xrzsp = data[0]["input_1753770718579_5ndFj"] //签约客户联系电话

                            //项目信息
                            $this.model.select_1761619590973_biiy4 = data[0]["select_1753773720879_V5l4b"] //销售团队
                            $this.model.systemSelect_1761619590973_EK67n = data[0]["systemSelect_1761200168405_7dDJY"] //销售负责人
                            $this.model.systemSelect_1761619590973_SvBH6 = data[0]["systemSelect_1761305069111_62IrS"] //设计负责人
                            $this.model.systemSelect_1761619590973_JURIY = data[0]["systemSelect_1688608855355_l9XZc"] //项目经理
                            $this.model.select_1761619590973_YyCEl = data[0]["select_1753770836763_b8on7"] //所属行业
                            $this.model.select_1761619590973_lPS7j = nameArr //设备类型 字典处理
                            $this.model.input_1761619590973_VMj14 = data[0]["input_1753771944911_VdhU9"] //设备型号
                            $this.model.number_1761619590973_Qwt67 = data[0]["number_1753772044979_0mwZj"] //数量
                            $this.model.select_1761619590973_tGuJx = data[0]["select_1760507162335_mR1iu"] //币种
                            $this.model.input_1761619590973_FU5JE = data[0]["input_1758703429069_praGC"] //合同质保条款
                            $this.model.select_1761619590973_OTV1v = data[0]["select_1753772231534_wLP30"] //发货方式

                            //时间特殊处理
                            $this.model.datepicker_1761619590973_SUCgx = data[0]["datepicker_1688608834665_f8cZm"] //立项时间
                            $this.model.datepicker_1761619590973_WgfiB = data[0]["datepicker_1753771875511_JZrk0"] //项目交货期

                            //变更任务信息
                            $this.model.input_1761619590973_p0z6Q = data[0]["input_1690184649174_VbQou"] //项目地址
                            $this.model.textarea_1761619590972_TM6Ql = data[0]["textarea_1753772205602_rgWlA"] //售后服务
                            $this.model.textarea_1761619590973_3cmqQ = data[0]["textarea_1688609935588_Rztic"] //付款条件
                            $this.model.textarea_1761619590973_PV7dO = data[0]["textarea_1753772355571_qpoZy"] //项目描述

                            // 表体存在
                            for (let j = 0; j < data.length; j++) {
                                if(data[j]["body_id"] != null && data[j]["body_id"] !== "") {
                                    //处理表体; 构造 一条表体数据，push 进表格。
                                    $this.model["table_1761621684298_7OBB8"].push({
                                        body_id:$this.$util.uuid(),
                                        create_date:$this.$util.getFormatDate(),
                                        index_id:$this.model["table_1761621684298_7OBB8"].length>0?$this.model["table_1761621684298_7OBB8"][$this.model["table_1761621684298_7OBB8"].length-1].index_id+1:1,
                                        table_body_id:data[j]["bill_id"],
                                        body_1761621788838_DDwaS: data[j]["body_1688610447952_3wkmh"],//人员名称
                                        body_1761621804163_wwk07: data[j]["body_1688610485722_RuEWp"],//项目角色
                                        body_1761621816327_yXxna: data[j]["body_1688610524215_DAP8D"],//状态
                                        body_1761621999355_Xbb9y: data[j]["body_1688610546451_EAZeW"]//备注
                                    })
                                }
                            }

                            //执行附件复制操作
                            let attachmentParams = {
                                parentId: currentBillId, //项目立项 - id
                                whId: whId,
                                billId: $this.model.bill_id,//项目状态变更 - id
                                parentFileStrName: 'uploadFile_1688609943921_2JWsA', //项目立项-技术交接单
                                fileStrName: 'uploadFile_1709713440888_3j89u' //项目状态变更-技术交接单
                            };

                            return $this.$http.post('formsBusiness/copyTheAttachment/',
                                getFormData(attachmentParams)
                            ).then(attachmentRes => {
                                if (attachmentRes && attachmentRes.data && attachmentRes.data.code !== 280) {
                                    console.error("Attachment copy failed:", attachmentRes.data.message || "Unknown error");
                                    $this.$message.error("附件复制失败，请联系管理员！！！");
                                } else if (!attachmentRes) {
                                    console.error("Attachment copy returned empty response");
                                    $this.$message.error("附件复制无响应，请联系管理员！！！");
                                }
                            }).catch(error => {
                                console.error("Attachment copy exception:", error);
                                $this.$message.error("附件复制异常，请联系管理员！！！");
                            });
                        } else {
                            $this.$message.error("数据获取失败，请联系管理员！！！");
                        }
                    }).catch(error => {
                        console.error("Main request error:", error);
                        $this.$message.error("系统错误，请联系管理员！！！");
                    });
                }
            } else {
                $this.$message.error("未找到申请数据，请联系管理员！！！");
            }
        } else {
            $this.$message.error("未找到标签页数据，请联系管理员！！！");
        }
    }
}

main()

function getFormData(param) {
    const formData = new FormData();
    if (!param || Object.values(param).length <= 0) return formData;
    for (let k in param) {
        if (Object.prototype.toString.call(param[k]) === '[object String]') {
            formData.append(k, param[k])
        } else {
            formData.append(k, JSON.stringify(param[k]))
        }
    }
    return formData;
}
